package com.mukesh.ui;

import java.util.ArrayList;
import java.util.List;


import com.example.funsms.R;
import com.example.funsms.SmsReceiver;
import com.mukesh.ui.HorizontalView;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;

public class HorizontalListView extends Activity {

	private List drawables;
	private List<String>  smsList;
	private HorizontalImageAdapter imageAdapter;
	private HorizontalView listView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_horizontal_list_view);

		listView = (HorizontalView) findViewById(R.id.gallery);
		getDrawablesList();
		setupUI();
	}

	private void setupUI() {
		getListChat();
		
		imageAdapter = new HorizontalImageAdapter(this, drawables,smsList);

		listView.setAdapter(imageAdapter);
		
		
	}
	private void getListChat(){
		smsList = new ArrayList<String>();
		
		ContentResolver contentResolver = getContentResolver();
		Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inbox" ), null, null, null, null);

		int indexBody = cursor.getColumnIndex( SmsReceiver.BODY );
		int indexAddr = cursor.getColumnIndex( SmsReceiver.ADDRESS );
		int indexStatus = cursor.getColumnIndex(SmsReceiver.STATUS);
		if ( indexBody < 0 || !cursor.moveToFirst() ) return;
		
		smsList.clear();
		
		for(int i=0;i<20;i++){
			String str = cursor.getString( indexBody );
			int status = cursor.getInt(indexStatus);
			if(status != 0){
				smsList.add( str );
			}
			if(!cursor.moveToNext()){
				break;
			}
			
		}
		
	}
	private void getDrawablesList() {

		drawables = new ArrayList();
		drawables.add(getResources().getDrawable(R.drawable.face20));
		drawables.add(getResources().getDrawable(R.drawable.face4));

	}

}